package com.myecl.poker.rules.enums;

import java.util.Queue;

import com.myecl.poker.rules.Card;
import com.myecl.poker.state.Player;
import com.myecl.poker.util.Shuffle;



public enum BettingRound {
	PRE_FLOP, FLOP, TURN, RIVER;
	
	public void rotateQueue(Queue<Player> players, Player button) {
		assert players.contains(button);
		switch(this) {
			case PRE_FLOP: preFlop(players, button); break;	
			case FLOP: postFlop(players, button); break;
			case TURN: postFlop(players, button); break;
			case RIVER: postFlop(players, button); break;
		}
	}
	
	
	public static boolean checkCardNumber(BettingRound bettingRound, Card[] cards) {
		boolean result = cards != null
				&& ((bettingRound == BettingRound.PRE_FLOP && cards.length == 2)
				|| (bettingRound == BettingRound.FLOP && cards.length == 3)
				|| (bettingRound == BettingRound.TURN && cards.length == 1)
				|| (bettingRound == BettingRound.RIVER && cards.length == 1));
		return result;
	}
	
	
	
	private void preFlop(Queue<Player> players, Player button) {
		if (players.size() > 2) {
			Shuffle.rotateTo(players, button, 1);
		} else {
			Shuffle.rotateTo(players, button, 0);
		}
	}
	
	private void postFlop(Queue<Player> players, Player button) {
		Shuffle.rotateTo(players, button, 1);
	}	
	
	
	
	
	
	
	
	
	
	
	
}
